package com.example.module_base.Controll;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.example.module_base.Base.BaseActivity;
import com.example.module_base.R;

/**
 * Created by SJ on 2018/4/13.
 */

public class MyToolBar {
    private Toolbar toolbar;
    private Context activity;
    public MyToolBar(@NonNull Context activity){
        this.activity=activity;
    }
    //第一步
    public MyToolBar init(Toolbar toolbar){
        this.toolbar=toolbar;
        return init();
    }
    public MyToolBar init(){
        if (toolbar == null) {
            this.toolbar=new Toolbar(activity);
        }
        this.toolbar.setTitleTextColor(Color.WHITE);
        this.toolbar.setElevation(5.0f);

        this.toolbar.setSubtitleTextColor(Color.WHITE);
        this.toolbar.setBackgroundResource(R.color.colorPrimary);
        return this;
    }
    public MyToolBar addTitle(@NonNull String title){
        this.toolbar.setTitle(title);
        return this;
    }
    public MyToolBar addTitle(@NonNull String title,String subtitle){
        this.toolbar.setTitle(title);
        this.toolbar.setSubtitle(subtitle);
        return this;
    }
    public MyToolBar setOverflowIcon(){
        this.toolbar.setOverflowIcon(activity.getResources().getDrawable(R.drawable.ic_more_vert_black_24dp));
        return this;
    }
    public MyToolBar addLogo(){
        this.toolbar.setLogo(R.drawable.ic_logo_line);
        this.toolbar.setContentInsetStartWithNavigation(0);
        return this;
    }
    public MyToolBar setColor(@ColorRes int bgcolor, @ColorInt @ColorRes int titlecolor){
        toolbar.setTitleTextColor(titlecolor);
        toolbar.setBackgroundResource(bgcolor);
        return this;
    }
    public MyToolBar addMenu(int menu, Toolbar.OnMenuItemClickListener onMenuItemClickListener){
        toolbar.inflateMenu(menu);
        //设置选项菜单的菜单项的点击事件
        toolbar.setOnMenuItemClickListener(onMenuItemClickListener);
        return this;
    }
    //最后一步
    public Toolbar addHome(int home, View.OnClickListener onClickListener){
        switch (home){
            case 0://菜单
                toolbar.setNavigationIcon(R.drawable.fm_ic_qiniulogo);
                break;
            case 1://返回
                toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp);
                break;
            default:
                toolbar.setNavigationIcon(home);
                break;
        }
        toolbar.setNavigationOnClickListener(onClickListener);
        return toolbar;
    }

    //调用
    /**
     Toolbar toolbar=new MyToolBar(this)
         .init().addTitle("登陆")
         .addLogo()
         .setOverflowIcon()
         .addHome(0, new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        finish();
        }
        });
     this.addToolBar(binding.lineToolbar,toolbar);
     */
}
